<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Insert title here</title>
	</head>

	<e:View id="view">
	    <script type="text/javascript" src="<c:url value='/scripts/global.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/skin.js'/>"></script>
	    <script type="text/javascript">SkinUtil.getSkin();</script>
	    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
    
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
			<e:Dataset id="Dataset_Index" datasetDefinition="DatasetDefinition_zb.dsd" datasetRef="Dataset_Index" pageSize="10" loadDataCommand="Command_Load">
				 <e:Field name="indexId" dataType="string" label="指标ID" maxLength="32" required="true" validators="checkId"/>
				 <e:Field name="indexName" dataType="string" label="指标名称" maxLength="100"  required="true"/>
				 <e:Field name="indexDesc" dataType="string" label="指标说明" maxLength="200" />
				 <e:Field name="indexType" dataType="string" label="指标类型" maxLength="1" required="true" defaultValue="1" visible="false" />
				 <e:Field name="fitObject" dataType="string" label="适用范围" maxLength="4" dropDown="ListDropDown__FIT_OBJECT" required="true"/>
				 <e:Field name="statCycle" dataType="string" label="统计周期" maxLength="1" dropDown="ListDropDown__STAT_CYCLE" required="true"/>
				 <e:Field name="indexUnit" dataType="string" label="指标单位" maxLength="2" dropDown="ListDropDown__INDEX_UNIT" required="true"/>
				 <e:Field name="indexLevel" dataType="long" label="指标等级" maxLength="22" defaultValue="1" visible="false" />
				 <e:Field name="howDecimal" dataType="string" label="小数位数" maxLength="1" dropDown="ListDropDown__HOW_DECIMAL" required="true"/>
				  <e:Field name="formula" dataType="string" label="指标公式" maxLength="4000" visible="false"/>
				 <e:Field name="formulaSql" dataType="string" label="指标公式sql" maxLength="4000" visible="false"/>
				 <e:Field name="indexDepend" dataType="string" label="指标依赖关系" maxLength="1" visible="false"/>
				 <e:Field name="dataType" dataType="string" label="数据类型" maxLength="1" visible="false"/>
				  <e:Field name="storeDate" dataType="string" label="数据保存日期" maxLength="1" required="true" dropDown="ListDropDown__STAT_CYCLE" />
				 
				  <e:Field name="fromTableName" dataType="string" label="数据来源" maxLength="1" visible="false"/>
				   <e:Field name="fromColumnName" dataType="string" label="数据来源" maxLength="1" visible="false"/>
				    <e:Field name="fromCondition" dataType="string" label="数据来源" maxLength="1" visible="false"/>
				 <e:Field name="fromAvgType" dataType="string" label="数据来源" maxLength="1" visible="false"/>
				  <e:Field name="fromStatus" dataType="string" label="数据来源" maxLength="1" visible="false"/>
				
				 <e:Field name="sortNo" dataType="long" label="排序号" maxLength="22" required="true"/>
				 <e:Field name="remark" dataType="string" label="备注" maxLength="400" />
				 <e:Field name="createTime" dataType="date" label="创建时间" maxLength="7" readOnly="true"/>
				 <e:Field name="createUserId" dataType="string" label="创建人ID" maxLength="32" visible="false" readOnly="true"/>
				 <e:Field name="createUserName" dataType="string" label="创建人" maxLength="100" readOnly="true"/>
				 <e:Field name="createOrgId" dataType="string" label="创建机构ID" maxLength="32" visible="false" />
				 <e:Field name="createOrgName" dataType="string" label="创建机构" maxLength="100" readOnly="true"/>
				 <e:Field name="updateUserName" dataType="string" label="修改人" maxLength="100" readOnly="true"/>
				 <e:Field name="updateTime" dataType="date" label="修改时间" maxLength="7" readOnly="true"/>
			</e:Dataset>
			
			<e:Command id="Command_Save" action="com.longtop.perform.zb.index.web.IndexDlBaseEditAction" method="saveIndex" validateRequired="true"
					showHintInfoOnSuccess="false" onExecuteSuccess="Command_Save_onExecuteSuccess(command)">
				<e:DatasetInfo name="DatasetInfo1" alwayRefreshClient="true" submitType="changes" dataset="Dataset_Index"></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_Delete" action="com.longtop.perform.zb.index.web.IndexDlListAction" method="deleteIndex" validateRequired="false" 
					showHintInfoOnSuccess="false" onExecuteSuccess="Command_Delete_onExecuteSuccess(command)">
			</e:Command>
			
			<e:ListDropDown id="ListDropDown_indexType_0009" fixed="true" autoDropDown="true">
			</e:ListDropDown>
			
			<e:PatternValidator pattern="^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){1,31}$" id="checkId" errorMessage="ID必须为2位数以上，以字母开头的字母，下划线，数字的组合"></e:PatternValidator>
			
			<e:ListDropDown id="ListDropDown__FIT_OBJECT" fixed="true" autoDropDown="true">
			</e:ListDropDown>
			
			<e:ListDropDown id="ListDropDown__STAT_CYCLE" fixed="true" autoDropDown="true">
			</e:ListDropDown>
			<e:ListDropDown id="ListDropDown__INDEX_UNIT" fixed="true" autoDropDown="true">
			</e:ListDropDown>
			<e:ListDropDown id="ListDropDown__HOW_DECIMAL" fixed="true" autoDropDown="true">
			</e:ListDropDown>
		</div>

		<body>
			<e:Page id="ePage" action="com.longtop.perform.zb.index.web.IndexDlBaseEditAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
				<table style="width: 100%; height: 100%;" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
					<tr>
						<td valign="top" width="100%">
							<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
								<tr>
									<td>
										<e:GroupBox id="GroupBox1" caption="定量基础指标" style="height: 100%; width:100%;">
											<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" width="100%" align="center">
												<tr>
													<td align="center" colspan="4" >
														<e:Button id="Button_Save" caption="保存" style="width: 70px; height: 22px" onClick="Button_Save_onClick()" icon="/images/submit.gif"></e:Button>&nbsp;&nbsp;
														<e:Button id="Button_Delete" caption="删除" style="width: 70px; height: 22px" onClick="Button_Delete_onClick()" icon="/images/delete.gif"></e:Button>&nbsp;&nbsp;
														<e:Button id="Button_Back" caption="返回" style="width: 70px; height: 22px" onClick="Button_Back_onClick()" icon="/images/undo.gif"></e:Button>
													</td>
												</tr>	
												<tr>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_indexId" caption="指标ID"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_indexId" dataset="Dataset_Index" field="indexId" editorType="text" style="width:250px;"></e:Text>
													</td>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_indexName" caption="指标名称"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_indexName" dataset="Dataset_Index" field="indexName" editorType="text" style="width:250px;"></e:Text>
													</td>
												</tr>
												<tr>	
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_objectScope" caption="适用对象"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_objectScope" dataset="Dataset_Index" field="objectScope" style="width:250px;"  dropDown="ListDropDown_objectScope_0006"></e:Text>
													</td>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_indexUnit" caption="计量单位"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_indexUnit" dataset="Dataset_Index" field="indexUnit" style="width:250px;" dropDown="ListDropDown_indexUnit_0003"></e:Text>
													</td>
												</tr>
												<tr>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_precision" caption="计量精度"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_precision" dataset="Dataset_Index" field="precision" style="width:250px;"  dropDown="ListDropDown_precision_0004"></e:Text>
													</td>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_scale" caption="小数位数"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_scale" dataset="Dataset_Index" field="scale" style="width:250px;" dropDown="ListDropDown_scale_0005"></e:Text>
													</td>
												</tr>
												<tr>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_statCycle" caption="统计周期"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_statCycle" dataset="Dataset_Index" field="statCycle" style="width:250px;" dropDown="ListDropDown_statCycle_0001"></e:Text>
													</td>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_dataSource" caption="数据来源"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_dataSource" dataset="Dataset_Index" field="dataSource" style="width:250px;"  dropDown="ListDropDown_dataSource_0002"></e:Text>
													</td>
												</tr>
												<tr>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_sortNo" caption="排序号"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_sortNo" dataset="Dataset_Index" field="sortNo" style="width:250px;"></e:Text>
													</td>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_saveDate" caption="保存日期"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_saveDate" dataset="Dataset_Index" field="saveDate" style="width:250px;" dropDown="ListDropDown_saveDate_0007"></e:Text>
													</td>
												</tr>
												<tr>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_doDateType" caption="处理日期"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_doDateType" dataset="Dataset_Index" field="doDateType" style="width:250px;"  dropDown="ListDropDown_doDateType_0008"></e:Text>
													</td>
													<td align="left" colspan="2" id="specify_tr" style="display:none">
														<table cellspacing="0" cellpadding="0">
															<tr>
																<td align="right">
																	<e:Label id="Label_doDate" caption="指定处理日期"></e:Label>
																</td>
																<td>
																	<e:Text id="doDateType1" dropDown="ListDropDown_doDateType1_0010" />
																</td>
																<td id="ftd1" style="display:none">
																	每年第
																	<e:Text id="fmonth1" style="width:30" maxLength="2"></e:Text>
																	月
																	<e:Text id="fday1" style="width:30" maxLength="2"></e:Text>
																	日
																</td>
																<td id="ftd2" style="display:none">
																	每季第
																	<e:Text id="fmonth2" style="width:30" maxLength="2"></e:Text>
																	月
																	<e:Text id="fday2" style="width:30" maxLength="2"></e:Text>
																	日
																</td>
																<td id="ftd3" style="display:none">
																	每月第
																	<e:Text id="fday3" style="width:30" maxLength="2"></e:Text>
																	日
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr>	
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_indexDesc" caption="指标说明"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_indexDesc" dataset="Dataset_Index" field="indexDesc" editorType="textArea" style="width:250px;height:50px;"></e:Text>
													</td>
													<td align="right" nowrap="nowrap">
														<e:Label id="Label_remark" caption="备注"></e:Label>
													</td>
													<td align="left">
														<e:Text id="Text_remark" dataset="Dataset_Index" field="remark" editorType="textArea" style="width:250px;height:50px;"></e:Text>
													</td>
												</tr>
											</table>
										</e:GroupBox>
									</td>
								</tr>	
							</table>
						</td>
					</tr>
			    </table>
			</e:Page>
		</body>
	</e:View>
</html>	

<script type="text/javascript">
	//返回
	function Button_Back_onClick(){
		var tabName = "<%=request.getParameter("openerTabName") %>";
			var tabset = $J(parent.TabSet_Apps);
			returnToCustTab(tabset,tabName,true);
	}
	
	//保存
	function Button_Save_onClick(){
		var record = Dataset_Index.getCurrentRecord();
		if(record){
			Command_Save.execute();
		}else{
			alert("没有需要保存的数据");
		}
	}
	
	//删除成功
	function Command_Delete_onExecuteSuccess(command){
		alert("操作成功！");
		Button_Back_onClick();
	}
	
	//操作成功
	function Command_Save_onExecuteSuccess(command){
		alert("操作成功！");
		var indexId = command.parameters.getValue("indexId");
		var record = Dataset_Index.getCurrentRecord();
		if(record){
			if(record.getValue("indexId") == null || record.getValue("indexId") == ""||record.getValue("indexId") == "%@|$"){
				record.setValue("indexId",indexId);
			}
		}
	}
	
	function LookupDropDown_DoDate_onAfterSelect(dropdown,item,text){
			var itemValue=item.getValue();
			if(itemValue=='5'){
			document.getElementById('specify_tr').style.display = 'block';
			}
			else{
			document.getElementById('specify_tr').style.display = 'none';
			}
	}
	function ListDropDown_finishDat_onAfterSelect(dropdown,item,text){
		ListDropDown_onAfterSelect(dropdown,item,text,'f');
	}
	function ListDropDown_onAfterSelect(dropdown,item,text,type){
	    var itemValue=item.getValue();
	    var month='';
	    var day='';
	    var td1 = document.getElementById(type+ 'td1');
	    var td2 = document.getElementById(type+ 'td2');
	    var td3 = document.getElementById(type+ 'td3');
	    if (itemValue == 'Y'){
	        td1.style.display = 'block';
	        td2.style.display = 'none';
	        td3.style.display = 'none';
	        month = parseInt($J(type + 'month1'),10);
	        day = parseInt($J(type + 'day1'),10);
	    }else if (itemValue == 'Q'){
	        td1.style.display = 'none';
	        td2.style.display = 'block';
	        td3.style.display = 'none';
	        month = parseInt($J(type + 'month2'),10);
	        day = parseInt($J(type + 'day2'),10);
	    }else if (itemValue == 'M'){
	        td1.style.display = 'none';
	        td2.style.display = 'none';
	        td3.style.display = 'block';
	        month = 0;
	        day = parseInt($J(type + 'day3'),10);
	    }else{
	    	td1.style.display = 'none';
	        td2.style.display = 'none';
	        td3.style.display = 'none';
	    }
	    
	}
	//指定日期输入，校验日输入
	function checkDay(day){
	    if(day.trim() == '' || isNaN(day)){
	    	alert("日不能为空且必须为数字！");
	    	return '';
	    }
	    day = parseInt(day,10);
	    if(day <1 || day >30){
	    	alert("日必须为1到30！");
	    	return '';
	    }
	    else if (day < 10){
	    	day = '0' + day;
	    }
	    return day;
	}
	//指定日期输入，校验月输入 maxnum 3 （季）| 12（月）
	function checkMonth(month,maxnum){
	    if(month.trim() == '' || isNaN(month)){
	    	alert("月不能为空且必须为数字！");
	    	return '';
	    }
	    month = parseInt(month,10);
	    if(month <1 || month > maxnum){
	    	alert("月必须为1到" + maxnum);
	    	return '';
	    }
	    else if (maxnum == 12 && month < 10){
	    	month = '0' + month;
	    }
	    return month;
	}

	//若为指定日期，给dataset赋值
	function getCycleDate(){
		//若处理日期为其他指定日期，则指定日期必填
	    var finishDate = $J('Text_doDateType').getValue();
	    
	    if(finishDate == '5'){
	    	var finishDate2 = $J('doDateType1').getValue();
	    	//alert(finishDate2);
	    	var cycleDate = finishDate2;
	    	cycleDate = getDate(finishDate2,'f');
	    	if(cycleDate == ''){
	    	}
	    	//alert("cycleDate=" + cycleDate);
	    }else{
	    	cycleDate='1';
	    }
	    return cycleDate;
	}
	
	
	function getDate(dateType,type){
		var cycleDate = dateType;
		if(dateType == 'M'){
	    	var day =  $J(type + 'day3').getValue();
	    	day = checkDay(day);
	    	if(day == '') return '';
	    	cycleDate = cycleDate + '' + day;
	    }else if(dateType == 'Q'){
	    	var month = $J(type + 'month2').getValue();
	    	month = checkMonth(month,3);
	    	if(month == '') return '';
	    	var day = $J(type + 'day2').getValue();
	    	day = checkDay(day);
	    	if(day == '') return '';
	    	cycleDate = cycleDate + '' + month + '' + day;
	    }else if(dateType == 'Y'){
	    	var month = $J(type + 'month1').getValue();
	    	month = checkMonth(month,12);
	    	if(month == '') return '';
	    	var day = $J(type + 'day1').getValue();
	    	day = checkDay(day);
	    	if(day == '') return '';
	    	cycleDate = cycleDate + '' + month + '' + day;
	    }
	    //alert("theDate=" + cycleDate);
	    return cycleDate;
	}
	//保存
	function Button_Save_onClick(){
		var record = Dataset_Index.getCurrentRecord();
		if(record){
		    var ss=record.getValue("indexId");
		    var cycleDate=getCycleDate();
		    if(cycleDate==''){
		     	alert("请填写正确的指定处理日期！");
	    	return false;
		    }else{
		   	record.setValue("doDate",cycleDate);
		    }
		   // var dataType = document.getElementById('dataType').value;
		    //if (dataType == '2'){  //小数
		    //	record.setValue("scale","2");
		    //}
		 	record.setValue("indexType","2");
		  	Command_Save.execute();
		}else{
			alert("没有需要保存的数据");
		}
	}
	
	function ePage_onAfterLoadPage(){
		var indexId= $J('Text_indexId').getValue();
		if(indexId!=null&&indexId!=""){
				var field = Dataset_Index.getField("indexId");
				field.setReadOnly(true);
				
				field = Dataset_Index.getField("indexName");
				field.setReadOnly(true);
				
				field = Dataset_Index.getField("objectScope");
				field.setReadOnly(true);
			}
			var doDateType=$J('Text_doDateType').getValue();
			if(doDateType=='5'){
				var doDate=$J('Dataset_Index').getValue("doDate");
				var doDateType1 =$J('doDateType1');
				doDateType1.setValue(doDate.substring(0,1));
				doDateType1.render();
				var doDateValue=doDateType1.getValue();
				var td1 = document.getElementById('ftd1');
		    	var td2 = document.getElementById('ftd2')
		    	var td3 = document.getElementById('ftd3');
				if(doDateValue=='M'){
					td1.style.display = 'none';
			        td2.style.display = 'none';
			        td3.style.display = 'block';
			        var day=doDate.substring(1,doDate.length()-1);
			        $J('fday3').setValue(day);
			        
				}
				if(doDateValue=='Q'){
					td1.style.display = 'none';
			        td2.style.display = 'block';
			        td3.style.display = 'none';
			        var month=doDate.substring(1,2);
			        var day=doDate.substring(2,4);
			        $J('fmonth2').setValue(month)
			        $J('fday2').setValue(day);
				}
				if(doDateValue=='Y'){
					td1.style.display = 'block';
			        td2.style.display = 'none';
			        td3.style.display = 'none';
			        var month=doDate.substring(1,3);
			        var day=doDate.substring(3,5);
			        $J('fmonth1').setValue(month)
			        $J('fday1').setValue(day);
				}
				document.getElementById('specify_tr').style.display = 'block';
			}
		}
</script>